<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#login").click(function(){
            var userid = $("#userid").val();
            var password = $("#password").val();
            $.ajax({
                url: "login/login",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                type: "post",
                ContentType: 'text/plain',
                dataType: "json",
                data: {
                    "userid": userid,
                    "password":password,
                },
                success: function (data) {
                    if (data.status == "S") {
                        console.log(data.data.token)
                        setCookies('vat_login_token', data.data.token)
                        window.location.href = "index.html";
                    } else {
                        $("#result").attr('value',data.msg);
                    }
                },
                error: function (err, a, b) {
                    console.log(err);
                }
            });
        });
    });
    function setCookies(name, value){
        document.cookie = name + "=" + value;
    }

</script>
<body>
登录
<form>
    <div class="form-group">
        <input type="text" placeholder="请输入用户名" id="userid" >
    </div>
    <div class="form-group">
        <input type="password" placeholder="请输入密码" id="password" >
    </div>
    <a href="javascript:;" class="btn show mt20" id="login" >登录</a>
    <input type="text" id="result" value='' ></input>
</form>
</body>
</html>
